// File:			R2.h
// Authors:			Richard Burris, Joshua Douty
// Purpose:			Header file for R2
// Version:        	3.0
// Date:			11/03/2011


//#include "mpx_supt.h"
//#include "R1.h"
//#include "R2.h"
//#include "R3.h"
//#include "R4.h"
//#include "R6.h"
//#include "COMHAND.h"

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define NAMESIZE 10 //max name size for a process name

#define SYSTEM 2
#define APPLICATION 1

//RUN STATES
#define RUN 1
#define READY 2
#define BLOCKED 3
#define NOTSUSPEND 4
#define SUSPEND 5

//PROCESS clas FLAGS
#define APPLICATION 1
#define SYSTEM 2
#define STACKSIZE 4096
#define UPPERPRI 127
#define LOWERPRI -128

struct PCB {
	char name[NAMESIZE];	//name of the process
	int clas;				//the clas of the process( 1 = system.  0 = user)
	int priority;			//The priority of the process(-127 = lowest, 128 = highest)
	int stateR;				//The running state 1=Running, 2=ready, 3=blocked
	int stateS;				//The running/suspended state of the process: 4=not suspended, 5=suspended
	struct PCB* after;		//Pointer to the PCB behind
	struct PCB* before;		//pointer to the PCB in front of
	
	unsigned char* sTop;
	unsigned char* sBase;
	//unsigned char stack[STACKSIZE];
	unsigned char* mBase;
	unsigned char* mTop;
	int memSize;
	unsigned char* loadAddr;
	unsigned char* executeAddr;
};
typedef struct PCB Proc_Con_Block;
typedef Proc_Con_Block* PCB_Pointer;	


typedef struct context{ //almost all the registers on the CPU, save for ss and sp
	unsigned int BP, DI, SI, DS, ES;
	unsigned int DX, CX, BX, AX;
	unsigned int IP, CS, FLAGS;
}context;


//PCB_Pointer allocate_PCB();
int freePCB(PCB_Pointer pro);
PCB_Pointer findQ(PCB_Pointer q, char* na);
PCB_Pointer findPCB(char* nam);
void insert(PCB_Pointer* q, PCB_Pointer pro);
void insertPCB(PCB_Pointer pro);
void insertReady(PCB_Pointer pro);
void removePCB(PCB_Pointer pro);
PCB_Pointer setupPCB(char* nam, int pri, int cla);


PCB_Pointer createPCB(char* param, char arg); 
int deletePCB(char* param, char arg); 
int blockPCB(char* param, char arg); 
int unblockPCB(char* param, char arg); 
int suspendPCB(char* param, char arg); 
int resumePCB(char* param, char arg); 
int setPriorityPCB(char* param, char arg); 
int showPCB(char* param, char arg); 
void showQPCB(PCB_Pointer q); 
int showAllPCB(char* param, char arg); 
int showReadyPCB(char* param, char arg); 
int showBlockedPCB(char* param, char arg); 
PCB_Pointer getQueuePTR(int num);


//Post R2 funcitons
int deleteAllPCB();
int deletePCB2(PCB_Pointer pre);
PCB_Pointer createPCB2(char* processName, int intClass, int intPri );